const vm = require('vm');
const context = { x: 2 };
vm.createContext(context);

const script = new vm.Script(
  `for(let i = 0; i < 100000000; i++) x += 1;`,
  { filename: 'tom.js' }
);

script.runInContext(context, { timeout: 1000 }); // 上面的 script 执行会超时
